// Using county level demographic and socioeconomic
// data for robustness checks.
//
// Jeff Shrader & Matthew Gibson
// Creation date: 2014-02-11
// Time-stamp: "2014-07-03 16:34:11 jgs"


// Preliminaries
clear

local work "/DIRECTORY"

capture log close
log using "`work'/logs/robustness_models.log", replace
set more off
set matsize 800
timer clear 1
timer on 1


// County data
use "`work'/data/demographics/demographics_comb.dta", clear
drop if name == ""
drop if sunset_time > 19.1

gen delta_labor_force = civilian_labor_force_2010 - civilian_labor_force_2000
gen poverty_rate_2011 = povall_2011/pop_estimate_2011

foreach i of varlist pop_estimate_2012 n_pop_chg_2012 r_net_mig_2012 povall_2011 delta_labor_force unemployment_rate_2012 poverty_rate_2011 {
   gen `i'_d = `i'/area_mi
   gen ln_`i'_d = ln(`i'_d)
   gen ln_`i' = ln(`i')
   gen `i'_p = `i'/pop_estimate_2012
   gen ln_`i'_p = ln(`i'_p)
}

label var pop_estimate_2012 "Population"
label var n_pop_chg_2012 "Population change"
label var r_net_mig_2012 "Net migration"
label var povall_2011 "Poverty"
label var civilian_labor_force_2012 "Labor force"

label var delta_labor_force "Labor force change"


// To use
label var ln_pop_estimate_2012_d "Log pop. density"
label var n_pop_chg_2012_d "Pop. density change"
label var n_pop_chg_2012_p "Pop. change frac."
label var ln_poverty_rate_2011 "Log poverty rate"
label var r_net_mig_2012_p "Net migration frac."
label var delta_labor_force_p "Labor force change"
label var unemployment_rate_2012 "Unemployment rate"

label var tzdistance "TZ distance"
gen tzd_lat = tzdistance*latitude
label var tzd_lat "TZ dist.$\times$ lat."
label var sunset_time "Sunset time"

eststo drop *
foreach i of varlist ln_pop_estimate_2012_d n_pop_chg_2012_p r_net_mig_2012_p  {
   regress `i' sunset_time, vce(robust)
   eststo
}
esttab using "`work'/tables/US_robust_county1.tex", ///
  star(* 0.10 ** 0.05 *** 0.01) ///
  addnotes("Standard errors clustered at state level.") ///
  drop(_cons) ///
  title("Linear ATUS Estimates") ar2 se noconstant nonumbers nogaps label tex fragment replace


eststo drop *
foreach i of varlist ln_poverty_rate_2011 delta_labor_force_p unemployment_rate_2012 {
   regress `i' sunset_time /*latitude*/, vce(robust)
   eststo
}
esttab using "`work'/tables/US_robust_county2.tex", ///
  star(* 0.10 ** 0.05 *** 0.01) ///
  addnotes("Standard errors clustered at state level.") ///
  drop(_cons) ///
  title("Linear ATUS Estimates") ar2 se noconstant nonumbers nogaps label tex fragment replace


